package com.kn.sys.controller;

import com.kn.common.model.PageBean;
import com.kn.common.model.R;
import com.kn.common.valid.AddGroup;
import com.kn.common.valid.EditGroup;
import com.kn.sys.dto.RoleDto;
import com.kn.sys.dto.UserDto;
import com.kn.sys.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhoudf
 * @create 2021-03-09 16:44
 */
@RestController
@RequestMapping("sys/role")
@RequiredArgsConstructor
@CrossOrigin
public class RoleController {
    private final RoleService roleService;

    @GetMapping("all")
    public R findAllRole() {
        return roleService.findAllRole();
    }
    @GetMapping
    public R list(PageBean pageBean, String name){
        return roleService.list(pageBean,name);
    }
    @PostMapping
    public R add(@Validated(AddGroup.class) @RequestBody RoleDto roleDto){
        return roleService.add(roleDto);
    }
    @DeleteMapping("{id}")
    public R delete(@PathVariable Long id){
        return roleService.delete(id);
    }
    @PutMapping("{id}")
    public R edit(@PathVariable Long id,@Validated(EditGroup.class)@RequestBody RoleDto roleDto){
        return roleService.edit(id,roleDto);
    }
}

